import axios from "axios";
// import router from './router';
import router from "@/router";

// let baseURL = process.env.NODE_ENV === 'development' ? '/' : window.CUIT_server.API_ROOT;
// let timeout = window.CUIT_server.TIMEOUT;
let http = axios.create({
  baseURL: "http://yang1yu.site:8080",
  // baseURL:"http://127.0.0.1:8080",
  timeout: 1000000, // withCredentials: true,
  headers: {
    "Content-Type": "application/json", // Authorization: 'Bearer ' + sessionStorage.getItem('token')
    // 'token':sessionStorage.getItem("token")
  },
});

http.interceptors.request.use(
  function (config) {
    return config;
  },
  function (error) {
    return Promise.reject(error);
  }
);

http.interceptors.response.use(
  function (response) {
    if (response.data.code == 10000) {
      console.log("token 非法");
      router.replace({ path: "/" });
    }
    return response;
  },
  function (error) {
    return Promise.reject(error);
  }
);

export default http;
